package com.sc.config;

import java.io.IOException;

import org.beetl.core.resource.WebAppResourceLoader;
import org.beetl.ext.spring.BeetlGroupUtilConfiguration;
import org.beetl.ext.spring.BeetlSpringViewResolver;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.DefaultResourceLoader;

@Configuration
public class WebConfig {

	@Bean
	public BeetlSpringViewResolver beetlView() {
		BeetlGroupUtilConfiguration configuration = new BeetlGroupUtilConfiguration();
		DefaultResourceLoader resourceLoader = new DefaultResourceLoader();
		String viewPath = null;
		try {
			viewPath = resourceLoader.getResource("/templates").getFile().getPath();
			configuration.setResourceLoader(new WebAppResourceLoader(viewPath));
		} catch (IOException e) {
			throw new RuntimeException("spring.beetl.viewDir : " + viewPath + " ,that view path is not exists.");
		}

		configuration.init();

		BeetlSpringViewResolver springViewResolver = new BeetlSpringViewResolver();
		springViewResolver.setPrefix("/");

		springViewResolver.setSuffix(".html");

		springViewResolver.setContentType("text/html;charset=UTF-8");

		springViewResolver.setConfig(configuration);
		return springViewResolver;
	}
	
}
